﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Santa_sAdventure.Model.Enums;
using Microsoft.Xna.Framework.Audio;

namespace Santa_sAdventure.Model
{
    class Model
    {
        // Classes
        private Level m_level;
        private Player m_player;
        private ContentManager m_content;

        internal Model(ContentManager a_content)
        {
            // Makes a new player with animations
            Texture2D playerRunTexture = a_content.Load<Texture2D>("Images/Player/player-run");
            Texture2D playerJumpTexture = a_content.Load<Texture2D>("Images/Player/player-jump");
            Texture2D playerIdleTexture = a_content.Load<Texture2D>("Images/Player/Idle");
            Texture2D playerDieTexture = a_content.Load<Texture2D>("Images/PLayer/die");
            m_player = new Player(playerRunTexture, playerJumpTexture, playerIdleTexture, playerDieTexture, a_content.Load<SoundEffect>("Sounds/Events/snow-walking"));
            m_player.CreateNewPlayer();

            m_content = a_content;
        }

        // Can player jump?
        internal void IsJumpPossible()
        {
            if (m_player.CanJump)
            {
                m_player.Jump();
            }
        }

        // Move the player Left
        internal void MovePlayerLeft(float a_elapsedTimeSeconds)
        {
            m_player.MoveLeft(a_elapsedTimeSeconds);
        }

        // Move the player Right
        internal void MovePlayerRight(float a_elapsedTimeSeconds)
        {
            m_player.MoveRight(a_elapsedTimeSeconds);
        }

        // Update
        internal void Update(float a_totalSeconds)
        {
            // Update the level
            m_level.Update(a_totalSeconds);

            // Update player
            m_player.Update(a_totalSeconds);
        }

       

        // Returns new level
        internal Level GetNewLevel(string a_levelString, int a_levelIndex)
        {
            m_level = new Level(a_levelString, m_content, a_levelIndex);
            m_player.StartPosition = m_level.PlayerStartPosition;
            m_player.Position = m_level.PlayerStartPosition;
            m_player.CreateNewPlayer();
            return m_level;
        }

        // Returns Level
        internal Level GetLevel()
        {
            return m_level;
        }

        // Returns the player
        internal Player GetPlayer()
        {
            return m_player;
        }

        // Make the player stand still
        internal void StandStill()
        {
            m_player.StandStill();
        }

        // Return all the enemies in the level
        internal List<Enemy> GetEnemies()
        {
            return m_level.GetEnemies();
        }
    }
}
